package com.rocksdata.mc.ui.fragment;


import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.ctz.commonframe.ui.BaseFragment;
import com.rocksdata.mc.business.BusinessManager;
import com.rocksdata.mc.entity.CampusAppInfo;
import com.rocksdata.mc.R;
import com.rocksdata.mc.business.CampusAppManager;
import com.rocksdata.mc.business.UserInfoManager;
import com.rocksdata.mc.ui.adapter.ApplicationListAdapter;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 陈堂正 on 2016/11/24.
 */
@ContentView(R.layout.fragment_found)
public class FoundFragment extends BaseFragment {
    @ViewInject(R.id.tv_title_middle)
    private TextView tvTitle;
    @ViewInject(R.id.lv_found)
    private ListView lvFound;

    private List<CampusAppInfo> appList = new ArrayList<CampusAppInfo>();
    private ApplicationListAdapter adapter;

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        tvTitle.setText("发现");
        adapter = new ApplicationListAdapter(mContext, appList);
        lvFound.setAdapter(adapter);
        lvFound.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                CampusAppInfo info = adapter.getItem(position);
                CampusAppManager.skipToChildApplication(mContext, info);
            }
        });
        super.onViewCreated(view, savedInstanceState);
        getAppList();
    }

    @Override
    protected void onVisible() {
        super.onVisible();
        getAppList();
    }

    private void getAppList(){
//        if (appList.size() == 0) {
//            if(!BusinessManager.getUserInfoManager().isVisitor()) {
//                appList.add(new CampusAppInfo("空闲教室", R.mipmap.ic_app_free_classroom));
//                appList.add(new CampusAppInfo("空闲实训室", R.mipmap.ic_app_training_room));
//                appList.add(new CampusAppInfo("班车时刻表", R.mipmap.ic_app_shuttle_bus));
//                appList.add(new CampusAppInfo("投票", R.mipmap.ic_app_vote));
//                appList.add(new CampusAppInfo("问卷", R.mipmap.ic_app_questionnaire));
//                appList.add(new CampusAppInfo("扫一扫", R.mipmap.ic_app_scan));
//                appList.add(new CampusAppInfo("搜周边", R.mipmap.ic_app_nearby));
//                appList.add(new CampusAppInfo("校长信箱", R.mipmap.ic_app_email));
//                appList.add(new CampusAppInfo("漂流瓶", R.mipmap.ic_app_drift_bottle));
//            }else{
//                appList.add(new CampusAppInfo("扫一扫", R.mipmap.ic_app_scan));
//                appList.add(new CampusAppInfo("搜周边", R.mipmap.ic_app_nearby));
//            }
//            List<CampusAppInfo> list = BusinessManager.getApplicationManager().getAppList(CampusAppInfo.MODULE_FOUND,
//                    UserInfoManager.getCurrentUserType(), UserInfoManager.isVisitor(), true, false);
        appList.clear();
//        appList.addAll(list);
//        }
        adapter.notifyDataSetChanged();
    }
}
